
package system.base;

import framework.core.*;
import system.data.*;
/*
	Author    :chengbiao.he
	CreateTime:2008-02-23 14:54:14
*/
public class BillSequenceSrv extends IHandler
{

	public BillSequenceSrv() 
	{
		super();
	}
	private void deleteBillSequence(DBConnection con,SrvContext context) throws Exception
	{
		String[] ids = context.getParameterValues("ids");
		BillSequence obj = null;
		for(int i=0;i<ids.length;i++)
		{
			obj = BillSequence.fetch(con,ids[i]);
			if(obj!=null) obj.delete(con);
		}
	}
	private void saveBillSequence(DBConnection con,SrvContext context,ILoginContext loginContext) throws Exception
	{
		String id = context.getString("Id",null);
		BillSequence obj;
		if((id==null)||(id.equals("")))   //add
		{
			obj = BillSequence.fetch();
    	}
    	else                     //update
    	{
    		obj = BillSequence.fetch(con,id);
    	}
		BillSequencePageData data = (BillSequencePageData)PageData.fromForm(context,BillSequencePageData.class);
		context.setValue("BillSequencePageData",data);
		obj.fill(data);
		obj.save(con);
	}
	private void listBillSequence(DBConnection con,SrvContext context,String path) throws Exception
	{
		BillSequenceSearchEvent event = (BillSequenceSearchEvent)SearchEvent.fromForm(context,BillSequenceSearchEvent.class);
		context.setSessionValue("BillSequenceSearchEvent",event);
		context.setNextUrl(path+"BillSequenceList.jsp");
	}
	private void backBillSequence(DBConnection con,SrvContext context,String path) throws Exception
	{
		context.setNextUrl(path+"BillSequenceList.jsp");
	}
	
	public void doAction(DBConnection con,SrvContext context,ILoginContext loginContext) throws Exception
	{
		String action_code = context.getActionCode();
		String path = "/system/base/";
		
		if(action_code.equalsIgnoreCase("listBillSequence"))
		{
			listBillSequence(con,context,path);
			return;
		}
		if(action_code.equalsIgnoreCase("viewBillSequence"))
		{
			String id = context.getString("Id",null);
			BillSequence obj = BillSequence.fetch(con,id);
			context.setValue("BillSequence",obj);
			context.setNextUrl(path+"BillSequenceView.jsp");
			return;
		}
		if(action_code.equalsIgnoreCase("deleteBillSequence"))
		{
			context.setErrorUrl(path+"BillSequenceList.jsp");
			deleteBillSequence(con,context);
			backBillSequence(con,context,path);
			return;
		}
			
		if(action_code.equalsIgnoreCase("toAddBillSequence"))
		{
			BillSequence obj = BillSequence.fetch();
			BillSequencePageData data = (BillSequencePageData)PageData.fromTable(obj,BillSequencePageData.class);
			context.setValue("BillSequencePageData",data);
			context.setNextUrl(path+"BillSequenceEdit.jsp");
			return;
		}
		if(action_code.equalsIgnoreCase("toUpdateBillSequence"))
		{
			String id = context.getString("Id",null);
			BillSequence obj = BillSequence.fetch(con,id);
			BillSequencePageData data = (BillSequencePageData)PageData.fromTable(obj,BillSequencePageData.class);
			context.setValue("BillSequencePageData",data);
			context.setNextUrl(path+"BillSequenceEdit.jsp");
			return;
		}
		if(action_code.equalsIgnoreCase("toCopyBillSequence"))
		{
			String id = context.getString("Id",null);
			BillSequence obj = BillSequence.copy(BillSequence.fetch(con,id));
			BillSequencePageData data = (BillSequencePageData)PageData.fromTable(obj,BillSequencePageData.class);
			context.setValue("BillSequencePageData",data);
			context.setNextUrl(path+"BillSequenceEdit.jsp");
			return;
		}
		if(action_code.equalsIgnoreCase("saveBillSequence"))
		{
			context.setErrorUrl(path+"BillSequenceEdit.jsp");
			saveBillSequence(con,context,loginContext);
			backBillSequence(con,context,path);
			return;
		}
		if(action_code.equalsIgnoreCase("saveAndNewBillSequence"))
		{
			context.setErrorUrl(path+"BillSequenceEdit.jsp");
			saveBillSequence(con,context,loginContext);
			BillSequence obj = BillSequence.fetch();
			BillSequencePageData data = (BillSequencePageData)PageData.fromTable(obj,BillSequencePageData.class);
			context.setValue("BillSequencePageData",data);
			context.setNextUrl(path+"BillSequenceEdit.jsp");			
			return;
		}
		if(action_code.equalsIgnoreCase("backListBillSequence"))
		{
			backBillSequence(con,context,path);
			return;
		}
		
		//add by chengbiao.he start

		//add by chengbiao.he end

		Logger.throwException("BillSequenceSrv","unknown action_code="+action_code);
	}
}
